package leetcode;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

/**
 * @author cino
 * justCode
 */
public class leetcode80 {

    @Test
    public void test(){
        // int[] nums = {1,1,1,2,2,3};
        int[] nums = {0,0,1,1,1,1,2,3,3};
        System.out.println(removeDuplicates(nums));
    }

    public int removeDuplicates(int[] nums) {
        HashMap<Integer, Integer> map = new HashMap<>();
        int index = 0;
        for (int i = 0 ; i < nums.length ; i++){
            if (!map.containsKey(nums[i])){
                map.put(nums[i],1);
                nums[index++] = nums[i];
            }else {
                int count = map.get(nums[i]);
                if (count < 2){
                    map.put(nums[i], count+1);
                    nums[index++] = nums[i];
                }
            }
        }
        return index;
    }
}
